package t03;

/**
 * 小时工
 */
public class HourlyEmployee extends Employee {
    private double hourlySalary;// 每小时的工资
    private int workingHours;// 工作时长

    public HourlyEmployee(String name, int age, double hourlySalary, int workingHours) {
        // 将每小时的工资存入父类所提供的salary属性中
        super(name, age, hourlySalary);
        this.hourlySalary = hourlySalary;
        this.workingHours = workingHours;
    }

    @Override
    public double getSalary() {
        if (workingHours <= 40) {
            return hourlySalary * workingHours;
        } else {
            // 超过40小时部分的工资是平时小时工资的1.5倍
            return 40 * super.getSalary() + (workingHours - 40) * super.getSalary() * 1.5;
        }
    }
}
